package com.kele.pool;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author kele
 * @date 2021/10/12 14:19
 * @description Executors方式创建线程池
 */
public class ExecutorsTest {

    public static void main(String[] args) {
        ExecutorService executorSingle = Executors.newSingleThreadExecutor();//单一线程池
        ExecutorService executorFix = Executors.newFixedThreadPool(5);//定长线程池
        ExecutorService executorCache = Executors.newCachedThreadPool();//具有缓存的线程池

        try {
            for (int i = 0; i <5 ; i++) {
                executorCache.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"进来了");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorCache.shutdown();
        }
    }
}
